package com.cw.starter.sharding.config;

import org.apache.shardingsphere.sharding.algorithm.sharding.classbased.ClassBasedShardingAlgorithm;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.cw.starter.sharding.shardingrule.UserPreciseShardingAlgorithm;

import java.util.Properties;

/**
 * TODO
 *
 * @author chenw
 * @date 2021/11/3
 */
@Configuration
public class ShardingConfig {
    @Bean
    public ClassBasedShardingAlgorithm shardingAlgorithm(){
        ClassBasedShardingAlgorithm shardingAlgorithm = new ClassBasedShardingAlgorithm();
        Properties properties = new Properties();
        properties.setProperty("strategy", "standard");
        properties.setProperty("algorithmClassName", UserPreciseShardingAlgorithm.class.getName());
        shardingAlgorithm.init(properties);
        return shardingAlgorithm;
    }
}
